package com.recipes.app;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class RecipesUtil {
	
	public  static String INSDPATH = "/mnt/sdcard";
	//public  static String EXSDPATH = "/mnt/extSdCard";
	public  static String EXSDPATH = "/mnt/extsd";

	public static boolean copy(String file1, String file2) {
		File in = new File(file1);
		File out = new File(file2);
		if (!in.exists()) {
			return false;
		}

		if (!out.exists()) {
			out.mkdirs();
		} else {

		}
		System.out.println("cpoy start");
		File[] file = in.listFiles();
		FileInputStream fis = null;
		FileOutputStream fos = null;
		for (int i = 0; i < file.length; i++) {
			if (file[i].isFile()) {
				try {
					fis = new FileInputStream(file[i]);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				try {
					File f = new File(file2 + "/" + file[i].getName());
					fos = new FileOutputStream(f);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				int c;
				byte[] b = new byte[1024 * 5];
				try {
					while ((c = fis.read(b)) != -1) {
						fos.write(b, 0, c);
					}
					fis.close();
					fos.flush();
					fos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				// return true;
			} else
				copy(file1 + "/" + file[i].getName(),
						file2 + "/" + file[i].getName());
		}
		return true;
	}

}
